package com.llcbenwu.controller;

import com.llcbenwu.config.Result;
import com.llcbenwu.pojo.UserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;
import sun.dc.pr.PRError;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lilinchun
 * @date 2021/10/22 0022 16:33
 */
@RestController
@Api(value = "用户")
public class UserController {


    @Autowired
    private ProviderSignInUtils providerSignInUtils;


    @GetMapping("/me")
    @ApiOperation(value = "当前用户信息")
    public Result<Object> getMe() {

        return new Result<>(SecurityContextHolder.getContext().getAuthentication().getPrincipal());
    }


    @PostMapping("/user/regist")
    @ApiOperation(value = "当前用户信息")
    public void regisUser (UserDTO user, HttpServletRequest request) {
        //不管是注册用户还是绑定用户，都会拿到一个用户唯一标识
        String userId = user.getUserName();
        providerSignInUtils.doPostSignUp(userId, new ServletWebRequest(request));
    }


    @PostMapping("/user")
    @ApiOperation(value = "用户post")
    public Result<String> getUser() {
        System.out.println("15465789798");
        return new Result<>("测试成功");
    }

    @GetMapping("/user/1")
    @ApiOperation(value = "用户post")
    public Result<String> getUsero() {
        System.out.println("444444444444444444");
        return new Result<>("测试成功");
    }
}
